<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>配置信息 | anyang的博客</title>
    <meta name="description" content="千里之行,始于足下">
    <meta name="generator" content="VuePress 1.3.1">
    <link rel="icon" href="/img/favicon.ico">
  <script charset="utf-8" src="/js/main.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.2/jquery.fancybox.min.js"></script>
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.2/jquery.fancybox.min.css">
  <meta name="keywords" content="福小林,奔奔,ourLang,CentOS,JAVA,vue组件,lsdCloud">
  <script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-146891701-1"></script>
  <script>window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'UA-146891701-1');</script>
  <script>var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?56eae8eec590ccaef1d5ff99d766f315";
        var s = document.getElementsByTagName("script")[0]; 
        s.parentNode.insertBefore(hm, s);
      })();</script>
    
    <link rel="preload" href="/assets/css/0.styles.9fff9873.css" as="style"><link rel="preload" href="/assets/js/app.1bc80adb.js" as="script"><link rel="preload" href="/assets/js/2.7c0608ab.js" as="script"><link rel="preload" href="/assets/js/98.9a231411.js" as="script"><link rel="prefetch" href="/assets/js/10.81caa2ab.js"><link rel="prefetch" href="/assets/js/100.05bb269d.js"><link rel="prefetch" href="/assets/js/101.3e18b4d6.js"><link rel="prefetch" href="/assets/js/102.c7d7ed9c.js"><link rel="prefetch" href="/assets/js/103.4c771ce7.js"><link rel="prefetch" href="/assets/js/104.a2acd367.js"><link rel="prefetch" href="/assets/js/105.63399350.js"><link rel="prefetch" href="/assets/js/106.8a4744cc.js"><link rel="prefetch" href="/assets/js/107.7739d796.js"><link rel="prefetch" href="/assets/js/108.8008ae33.js"><link rel="prefetch" href="/assets/js/109.01c63898.js"><link rel="prefetch" href="/assets/js/11.7b837560.js"><link rel="prefetch" href="/assets/js/110.ad01aca9.js"><link rel="prefetch" href="/assets/js/111.3d74db70.js"><link rel="prefetch" href="/assets/js/112.67f55c34.js"><link rel="prefetch" href="/assets/js/113.016cd3c0.js"><link rel="prefetch" href="/assets/js/114.860e4b2b.js"><link rel="prefetch" href="/assets/js/115.b2f26258.js"><link rel="prefetch" href="/assets/js/116.8bea67b4.js"><link rel="prefetch" href="/assets/js/117.20682843.js"><link rel="prefetch" href="/assets/js/118.86a22e16.js"><link rel="prefetch" href="/assets/js/119.ad518bea.js"><link rel="prefetch" href="/assets/js/12.8fd78714.js"><link rel="prefetch" href="/assets/js/120.f97dd86f.js"><link rel="prefetch" href="/assets/js/121.c5601b4a.js"><link rel="prefetch" href="/assets/js/122.2889645a.js"><link rel="prefetch" href="/assets/js/13.ebf26820.js"><link rel="prefetch" href="/assets/js/14.b92dca09.js"><link rel="prefetch" href="/assets/js/15.b3dcef45.js"><link rel="prefetch" href="/assets/js/16.50378990.js"><link rel="prefetch" href="/assets/js/17.056bba2b.js"><link rel="prefetch" href="/assets/js/18.9047bb38.js"><link rel="prefetch" href="/assets/js/19.ab53b0fe.js"><link rel="prefetch" href="/assets/js/20.fe0b8af0.js"><link rel="prefetch" href="/assets/js/21.20a702f3.js"><link rel="prefetch" href="/assets/js/22.0ee08d29.js"><link rel="prefetch" href="/assets/js/23.02039a9a.js"><link rel="prefetch" href="/assets/js/24.363d3d74.js"><link rel="prefetch" href="/assets/js/25.dd6b101e.js"><link rel="prefetch" href="/assets/js/26.20493714.js"><link rel="prefetch" href="/assets/js/27.708723e5.js"><link rel="prefetch" href="/assets/js/28.4561834a.js"><link rel="prefetch" href="/assets/js/29.15cfcf5f.js"><link rel="prefetch" href="/assets/js/3.8d39d40c.js"><link rel="prefetch" href="/assets/js/30.04ab69de.js"><link rel="prefetch" href="/assets/js/31.b11c4302.js"><link rel="prefetch" href="/assets/js/32.81ae74ee.js"><link rel="prefetch" href="/assets/js/33.ddf09cc0.js"><link rel="prefetch" href="/assets/js/34.bc3549f7.js"><link rel="prefetch" href="/assets/js/35.4a0e0ebd.js"><link rel="prefetch" href="/assets/js/36.961a1c50.js"><link rel="prefetch" href="/assets/js/37.d8658de5.js"><link rel="prefetch" href="/assets/js/38.f76063aa.js"><link rel="prefetch" href="/assets/js/39.73edd08f.js"><link rel="prefetch" href="/assets/js/4.916af9bf.js"><link rel="prefetch" href="/assets/js/40.72314bff.js"><link rel="prefetch" href="/assets/js/41.c5eb1147.js"><link rel="prefetch" href="/assets/js/42.07aeafbb.js"><link rel="prefetch" href="/assets/js/43.c4a652ba.js"><link rel="prefetch" href="/assets/js/44.91fbe22b.js"><link rel="prefetch" href="/assets/js/45.6eecf0c4.js"><link rel="prefetch" href="/assets/js/46.81b7f108.js"><link rel="prefetch" href="/assets/js/47.b4468ab3.js"><link rel="prefetch" href="/assets/js/48.df205f23.js"><link rel="prefetch" href="/assets/js/49.7df59fa3.js"><link rel="prefetch" href="/assets/js/5.4fcd540a.js"><link rel="prefetch" href="/assets/js/50.0dc2fc5b.js"><link rel="prefetch" href="/assets/js/51.1ffabe54.js"><link rel="prefetch" href="/assets/js/52.2269d284.js"><link rel="prefetch" href="/assets/js/53.81b23843.js"><link rel="prefetch" href="/assets/js/54.b3249def.js"><link rel="prefetch" href="/assets/js/55.50dcf2af.js"><link rel="prefetch" href="/assets/js/56.c399c272.js"><link rel="prefetch" href="/assets/js/57.024f1dbb.js"><link rel="prefetch" href="/assets/js/58.680c6cf4.js"><link rel="prefetch" href="/assets/js/59.2291e9d7.js"><link rel="prefetch" href="/assets/js/6.7610d1d4.js"><link rel="prefetch" href="/assets/js/60.e59a26c1.js"><link rel="prefetch" href="/assets/js/61.ff5c64e4.js"><link rel="prefetch" href="/assets/js/62.7d97062c.js"><link rel="prefetch" href="/assets/js/63.6456dc7e.js"><link rel="prefetch" href="/assets/js/64.0b055680.js"><link rel="prefetch" href="/assets/js/65.9f25601c.js"><link rel="prefetch" href="/assets/js/66.cd973084.js"><link rel="prefetch" href="/assets/js/67.9b8f9716.js"><link rel="prefetch" href="/assets/js/68.d6c1869a.js"><link rel="prefetch" href="/assets/js/69.0a3688dd.js"><link rel="prefetch" href="/assets/js/7.9ebbd956.js"><link rel="prefetch" href="/assets/js/70.22f48891.js"><link rel="prefetch" href="/assets/js/71.9eb4fda9.js"><link rel="prefetch" href="/assets/js/72.ca4fa80c.js"><link rel="prefetch" href="/assets/js/73.17d1ab37.js"><link rel="prefetch" href="/assets/js/74.139691db.js"><link rel="prefetch" href="/assets/js/75.08d0560f.js"><link rel="prefetch" href="/assets/js/76.61078c10.js"><link rel="prefetch" href="/assets/js/77.4482adcc.js"><link rel="prefetch" href="/assets/js/78.166f2c37.js"><link rel="prefetch" href="/assets/js/79.2c7d6b79.js"><link rel="prefetch" href="/assets/js/8.6f8916c2.js"><link rel="prefetch" href="/assets/js/80.80445c3f.js"><link rel="prefetch" href="/assets/js/81.14e3bae8.js"><link rel="prefetch" href="/assets/js/82.7dac687f.js"><link rel="prefetch" href="/assets/js/83.1dd2e78e.js"><link rel="prefetch" href="/assets/js/84.23b759de.js"><link rel="prefetch" href="/assets/js/85.7574f69f.js"><link rel="prefetch" href="/assets/js/86.102dac61.js"><link rel="prefetch" href="/assets/js/87.8f5d639e.js"><link rel="prefetch" href="/assets/js/88.e564cbbe.js"><link rel="prefetch" href="/assets/js/89.cd66eb78.js"><link rel="prefetch" href="/assets/js/9.baa162db.js"><link rel="prefetch" href="/assets/js/90.685c6878.js"><link rel="prefetch" href="/assets/js/91.b8d1b7ea.js"><link rel="prefetch" href="/assets/js/92.1faa374d.js"><link rel="prefetch" href="/assets/js/93.cf5ff33c.js"><link rel="prefetch" href="/assets/js/94.8a02aefb.js"><link rel="prefetch" href="/assets/js/95.1b379a5b.js"><link rel="prefetch" href="/assets/js/96.9fd67185.js"><link rel="prefetch" href="/assets/js/97.c5a6a5a1.js"><link rel="prefetch" href="/assets/js/99.5b344cab.js">
    <link rel="stylesheet" href="/assets/css/0.styles.9fff9873.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">anyang的博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/study-guide/introduction.html" class="nav-link">
  学习指南
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术分类" class="dropdown-title"><span class="title">技术分类</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/java/introduction.html" class="nav-link">
  Java
</a></li><li class="dropdown-item"><!----> <a href="/go/introduction.html" class="nav-link">
  Go
</a></li><li class="dropdown-item"><!----> <a href="/sql/introduction.html" class="nav-link">
  SQL
</a></li><li class="dropdown-item"><!----> <a href="/fhir/introduction.html" class="nav-link">
  FHIR
</a></li></ul></div></div><div class="nav-item"><a href="/blog/introduction.html" class="nav-link">
  个人博客
</a></div><div class="nav-item"><a href="/tool/developmentBox.html" class="nav-link">
  开发百宝箱
</a></div><div class="nav-item"><a href="/project/introduction.html" class="nav-link">
  项目分享
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="了解更多" class="dropdown-title"><span class="title">了解更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="http://wpa.qq.com/msgrd?v=3&amp;uin=1300378587&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  其他合作
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="http://www.lsdcloud.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  友情网站
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://github.com/ourlang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/anlexanyang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  码云
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://blog.csdn.net/qq_37493556" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/linkExchanges/introduction.html" class="nav-link">
  友情链接
</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/study-guide/introduction.html" class="nav-link">
  学习指南
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术分类" class="dropdown-title"><span class="title">技术分类</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/java/introduction.html" class="nav-link">
  Java
</a></li><li class="dropdown-item"><!----> <a href="/go/introduction.html" class="nav-link">
  Go
</a></li><li class="dropdown-item"><!----> <a href="/sql/introduction.html" class="nav-link">
  SQL
</a></li><li class="dropdown-item"><!----> <a href="/fhir/introduction.html" class="nav-link">
  FHIR
</a></li></ul></div></div><div class="nav-item"><a href="/blog/introduction.html" class="nav-link">
  个人博客
</a></div><div class="nav-item"><a href="/tool/developmentBox.html" class="nav-link">
  开发百宝箱
</a></div><div class="nav-item"><a href="/project/introduction.html" class="nav-link">
  项目分享
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="了解更多" class="dropdown-title"><span class="title">了解更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="http://wpa.qq.com/msgrd?v=3&amp;uin=1300378587&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  其他合作
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="http://www.lsdcloud.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  友情网站
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://github.com/ourlang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/anlexanyang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  码云
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://blog.csdn.net/qq_37493556" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/linkExchanges/introduction.html" class="nav-link">
  友情链接
</a></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/go/introduction.html" class="sidebar-link">Go语言</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Go教程</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Go Web框架</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/go/web/iris-go/start.html" class="sidebar-link">Iris概览</a></li><li><a href="/go/web/iris-go/config.html" class="active sidebar-link">配置信息</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_1-配置参数说明" class="sidebar-link">1 配置参数说明</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_1-1-configuration支持的配置项" class="sidebar-link">1.1 Configuration支持的配置项</a></li><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_1-2-程序内部配置示例" class="sidebar-link">1.2 程序内部配置示例</a></li></ul></li><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_2-通过toml配置文件" class="sidebar-link">2 通过TOML配置文件</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_2-1-什么是toml" class="sidebar-link">2.1 什么是toml</a></li><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_2-2-项目配置使用toml" class="sidebar-link">2.2 项目配置使用TOML</a></li><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_2-3-toml使用示例" class="sidebar-link">2.3 TOML使用示例</a></li></ul></li><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_3-通过yaml配置文件" class="sidebar-link">3 通过YAML配置文件</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_3-1-什么是yaml" class="sidebar-link">3.1 什么是yaml</a></li><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_3-2-项目配置使用yaml" class="sidebar-link">3.2 项目配置使用YAML</a></li><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_3-3-yaml使用示例" class="sidebar-link">3.3 YAML使用示例</a></li></ul></li><li class="sidebar-sub-header"><a href="/go/web/iris-go/config.html#_4-自定义配置文件" class="sidebar-link">4 自定义配置文件</a></li></ul></li><li><a href="/go/web/iris-go/handle-http.html" class="sidebar-link">处理HTTP请求</a></li><li><a href="/go/web/iris-go/route.html" class="sidebar-link">路由操作</a></li><li><a href="/go/web/iris-go/error-handling.html" class="sidebar-link">错误处理</a></li><li><a href="/go/web/iris-go/mvc.html" class="sidebar-link">MVC包的使用</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Go工具中间件</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="配置信息"><a href="#配置信息" class="header-anchor">#</a> 配置信息</h1> <blockquote><p>在<code>iris</code>框架开发中,初始化应用程序时已经使用了默认的配置值。作为开发者,我们可以不需要其他额外的配置就启动我们的应用程序。
如果开发者想要自己根据自己的需求进行配置,<code>iris</code>框架也是支持的,下面我们一起来学习一下<code>iris</code>框架所支持的配置方式。
现在主流的配置文件格式有：<code>xml</code>、<code>yaml</code>、<code>cnf</code>、<code>toml</code>、<code>json</code>等等格式。<code>xml</code>现在使用的已经不多,<code>cnf</code>格式的配置文件适合数据库的配置文件。</p></blockquote> <h2 id="_1-配置参数说明"><a href="#_1-配置参数说明" class="header-anchor">#</a> 1 配置参数说明</h2> <blockquote><p>在<code>iris</code>程序的全局<code>app</code>实例中，支持通过多种方式进行代码配置，途径是多样的。都是对<code>app</code>服务应用进行<code>Configuration</code>配置,提供应用配置的<code>Configuration</code>结构体定义所支持的配置项如下表：</p></blockquote> <ul><li>1、使用<code>app.Configure(iris.WithConfiguration(iris.Configuration{DisableStartuplog:false}))</code>来对整体应用进行配置项配置</li> <li>2、通过<code>app.Run</code>方法的第二个参数来进行相关的自定义配置项的配置，第二个参数的类型同1一致。</li></ul> <h3 id="_1-1-configuration支持的配置项"><a href="#_1-1-configuration支持的配置项" class="header-anchor">#</a> 1.1 Configuration支持的配置项</h3> <table><thead><tr><th style="text-align:left;">配置参数</th> <th>描述说明</th></tr></thead> <tbody><tr><td style="text-align:left;"><code>DisableInterruptHandler</code></td> <td>如果设置为<code>true</code>,当人为中断程序执行时,则不会自动正常将服务器关闭。如果设置为<code>true</code>,需要自己自定义处理。默认为<code>false</code>。</td></tr> <tr><td style="text-align:left;"><code>DisablePathCorrection</code></td> <td>该配置项表示更正并将请求的路径重定向到已注册的路径。比如：如果请求<code>/home/</code> 但找不到此<code>Route</code>的处理程序,然后路由器检查<code>/home</code>处理程序是否存在,如果是,（<code>permant</code>）将客户端重定向到正确的路径<code>/home</code>。默认为<code>false</code>。</td></tr> <tr><td style="text-align:left;"><code>EnablePathEscape</code></td> <td>该配置选项用于配置是否支持路径转义。适用于请求<code>url</code>中包含转义字符时进行配置。默认为<code>false</code>。</td></tr> <tr><td style="text-align:left;"><code>FireMethodNotAllowed</code></td> <td>默认为<code>false</code>。</td></tr> <tr><td style="text-align:left;"><code>DisableBodyConsumptionOnUnmarshal</code></td> <td>该设置选项用于配置读取请求数据的方法是否使用,如果设置为<code>true</code>,则表示禁用<code>context.UnmarshalBody</code>,<code>context.ReadJSON</code>以及<code>context.ReadXML</code>。默认为<code>false</code>。</td></tr> <tr><td style="text-align:left;"><code>DisableAutoFireStatusCode</code></td> <td>该配置变量为控制是否处理错误自动执行,如果为<code>true</code>,则不会进行错误自动执行。该配置项默认为<code>false</code>。</td></tr> <tr><td style="text-align:left;"><code>TimeFormat</code></td> <td>时间格式。默认格式为：<code>&quot;Mon, 02 Jan 2006 15:04:05 GMT&quot;</code></td></tr> <tr><td style="text-align:left;"><code>Charset</code></td> <td>字体格式选项。默认字体为：<code>&quot;UTF-8&quot;</code></td></tr></tbody></table> <h3 id="_1-2-程序内部配置示例"><a href="#_1-2-程序内部配置示例" class="header-anchor">#</a> 1.2 程序内部配置示例</h3> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token keyword">package</span> main

<span class="token keyword">import</span> <span class="token punctuation">(</span>
	<span class="token string">&quot;github.com/kataras/iris/v12&quot;</span>
<span class="token punctuation">)</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	app <span class="token operator">:=</span> iris<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	app<span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span><span class="token string">&quot;/&quot;</span><span class="token punctuation">,</span> <span class="token keyword">func</span><span class="token punctuation">(</span>ctx iris<span class="token punctuation">.</span>Context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		ctx<span class="token punctuation">.</span><span class="token function">HTML</span><span class="token punctuation">(</span><span class="token string">&quot;&lt;b&gt;Hello!&lt;/b&gt;&quot;</span><span class="token punctuation">)</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
	<span class="token comment">// [...]</span>
	<span class="token comment">//我们可以用这种方法单独定义我们的配置项</span>
	app<span class="token punctuation">.</span><span class="token function">Configure</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span><span class="token function">WithConfiguration</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span>Configuration<span class="token punctuation">{</span> DisableStartupLog<span class="token punctuation">:</span><span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token comment">//也可以使用app.run的第二个参数，第二个参数的类型同app.Configure()参数一致。</span>
	app<span class="token punctuation">.</span><span class="token function">Run</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span><span class="token function">Addr</span><span class="token punctuation">(</span><span class="token string">&quot;:9090&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> iris<span class="token punctuation">.</span><span class="token function">WithConfiguration</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span>Configuration<span class="token punctuation">{</span>
		DisableInterruptHandler<span class="token punctuation">:</span>           <span class="token boolean">false</span><span class="token punctuation">,</span>
		DisablePathCorrection<span class="token punctuation">:</span>             <span class="token boolean">false</span><span class="token punctuation">,</span>
		EnablePathEscape<span class="token punctuation">:</span>                  <span class="token boolean">false</span><span class="token punctuation">,</span>
		FireMethodNotAllowed<span class="token punctuation">:</span>              <span class="token boolean">false</span><span class="token punctuation">,</span>
		DisableBodyConsumptionOnUnmarshal<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
		DisableAutoFireStatusCode<span class="token punctuation">:</span>         <span class="token boolean">false</span><span class="token punctuation">,</span>
		TimeFormat<span class="token punctuation">:</span>                        <span class="token string">&quot;Mon, 02 Jan 2006 15:04:05 GMT&quot;</span><span class="token punctuation">,</span>
		Charset<span class="token punctuation">:</span>                           <span class="token string">&quot;UTF-8&quot;</span><span class="token punctuation">,</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token comment">//通过多参数配置 但是上面两种方式是我们最推荐的</span>
	<span class="token comment">// 我们使用With+配置项名称 如WithCharset(&quot;UTF-8&quot;) 其中就是With+ Charset的组合</span>
	<span class="token comment">//app.Run(iris.Addr(&quot;:9090&quot;), iris.WithoutStartupLog, iris.WithCharset(&quot;UTF-8&quot;))</span>
	<span class="token comment">//当使用app.Configure(iris.WithoutStartupLog, iris.WithCharset(&quot;UTF-8&quot;))设置配置项时</span>
	<span class="token comment">//需要app.run()面前使用</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br></div></div><h2 id="_2-通过toml配置文件"><a href="#_2-通过toml配置文件" class="header-anchor">#</a> 2 通过TOML配置文件</h2> <h3 id="_2-1-什么是toml"><a href="#_2-1-什么是toml" class="header-anchor">#</a> 2.1 什么是toml</h3> <blockquote><p><code>toml</code>是<code>Tom’s Obvious, Minimal Language</code>的缩写,<code>toml</code>是一种配置文件。<code>TOML</code>是前<code>GitHub CEO,Tom Preston-Werner</code>,于2013年创建的语言,其目标是成为一个小规模的易于使用的语义化配置文件格式。<code>TOML</code>被设计为可以无二义性的转换为一个哈希表<code>(Hash table)</code>。</p></blockquote> <h3 id="_2-2-项目配置使用toml"><a href="#_2-2-项目配置使用toml" class="header-anchor">#</a> 2.2 项目配置使用TOML</h3> <blockquote><p>具体的项目配置使用中,我们需要创建<code>iris.tml</code>类型的配置文件,并在程序中明确使用<code>toml</code>文件进行读取配置内容。如下所示：</p></blockquote> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token comment">//app := iris.New()</span>
app<span class="token punctuation">.</span><span class="token function">Configure</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span><span class="token function">WithConfiguration</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span><span class="token function">TOML</span><span class="token punctuation">(</span><span class="token string">&quot;./config/iris.tml&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="_2-3-toml使用示例"><a href="#_2-3-toml使用示例" class="header-anchor">#</a> 2.3 TOML使用示例</h3> <blockquote><p>我们在config目录下新建<code>iris.tml</code>文件，文件内容如下</p></blockquote> <div class="language-toml line-numbers-mode"><pre class="language-toml"><code>    <span class="token key property">DisablePathCorrection</span> <span class="token punctuation">=</span> <span class="token boolean">false</span>
    <span class="token key property">EnablePathEscape</span> <span class="token punctuation">=</span> <span class="token boolean">false</span>
    <span class="token key property">FireMethodNotAllowed</span> <span class="token punctuation">=</span> <span class="token boolean">true</span>
    <span class="token key property">DisableBodyConsumptionOnUnmarshal</span> <span class="token punctuation">=</span> <span class="token boolean">false</span>
    <span class="token key property">TimeFormat</span> <span class="token punctuation">=</span> <span class="token string">&quot;Mon, 01 Jan 2006 15:04:05 GMT&quot;</span>
    <span class="token key property">Charset</span> <span class="token punctuation">=</span> <span class="token string">&quot;UTF-8&quot;</span>
    <span class="token punctuation">[</span><span class="token table class-name">Other</span><span class="token punctuation">]</span>
        <span class="token key property">MyServerName</span> <span class="token punctuation">=</span> <span class="token string">&quot;iris&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token keyword">package</span> main
<span class="token keyword">import</span> <span class="token punctuation">(</span>
	<span class="token string">&quot;github.com/kataras/iris/v12&quot;</span>
<span class="token punctuation">)</span>
<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	app <span class="token operator">:=</span> iris<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	app<span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span><span class="token string">&quot;/&quot;</span><span class="token punctuation">,</span> <span class="token keyword">func</span><span class="token punctuation">(</span>ctx iris<span class="token punctuation">.</span>Context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		ctx<span class="token punctuation">.</span><span class="token function">HTML</span><span class="token punctuation">(</span><span class="token string">&quot;&lt;b&gt;Hello Toml!&lt;/b&gt;&quot;</span><span class="token punctuation">)</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
	<span class="token comment">// 通过文件配置 我们可以更加方便的切换开发环境配置和生产环境.</span>
	app<span class="token punctuation">.</span><span class="token function">Run</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span><span class="token function">Addr</span><span class="token punctuation">(</span><span class="token string">&quot;:9090&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> iris<span class="token punctuation">.</span><span class="token function">WithConfiguration</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span><span class="token function">TOML</span><span class="token punctuation">(</span><span class="token string">&quot;./config/iris.tml&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="_3-通过yaml配置文件"><a href="#_3-通过yaml配置文件" class="header-anchor">#</a> 3 通过YAML配置文件</h2> <h3 id="_3-1-什么是yaml"><a href="#_3-1-什么是yaml" class="header-anchor">#</a> 3.1 什么是yaml</h3> <blockquote><p><code>YAML</code>是专门用来写配置文件的语言,写法简洁、功能强大,比<code>JSON</code>格式还要方便。<code>Yaml</code>实质上是一种通用的数据串行化格式。<code>Yaml</code>的主要语法格式有以下几项：</p> <ul><li>大小写敏感。</li> <li>使用缩进表示层级关系。</li> <li>缩进时不允许使用<code>Tab</code>键，只允许使用空格。</li> <li>缩进的空格数目不受限制，相同层级的配置元素,左侧对齐即可。</li></ul></blockquote> <h3 id="_3-2-项目配置使用yaml"><a href="#_3-2-项目配置使用yaml" class="header-anchor">#</a> 3.2 项目配置使用YAML</h3> <blockquote><p>具体的项目配置使用中,我们需要创建<code>config.yml</code>类型的配置文件,并在程序中明确使用<code>yaml</code>文件进行读取配置内容。如下所示：</p></blockquote> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token comment">//app := iris.New()</span>
app<span class="token punctuation">.</span><span class="token function">Configure</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span><span class="token function">WithConfiguration</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span><span class="token function">TOML</span><span class="token punctuation">(</span><span class="token string">&quot;./config/config.tml&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="_3-3-yaml使用示例"><a href="#_3-3-yaml使用示例" class="header-anchor">#</a> 3.3 YAML使用示例</h3> <blockquote><p>我们在config目录下新建<code>config.tml</code>文件，文件内容如下</p></blockquote> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">DisablePathCorrection</span><span class="token punctuation">:</span> <span class="token boolean important">false</span>
<span class="token key atrule">EnablePathEscape</span><span class="token punctuation">:</span> <span class="token boolean important">false</span>
<span class="token key atrule">FireMethodNotAllowed</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">DisableBodyConsumptionOnUnmarshal</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">TimeFormat</span><span class="token punctuation">:</span> Mon<span class="token punctuation">,</span> 01 Jan 2006 15<span class="token punctuation">:</span>04<span class="token punctuation">:</span>05 GMT
<span class="token key atrule">Charset</span><span class="token punctuation">:</span> UTF<span class="token punctuation">-</span><span class="token number">8</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token keyword">package</span> main
<span class="token keyword">import</span> <span class="token punctuation">(</span>
	<span class="token string">&quot;github.com/kataras/iris/v12&quot;</span>
<span class="token punctuation">)</span>
<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	app <span class="token operator">:=</span> iris<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	app<span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span><span class="token string">&quot;/&quot;</span><span class="token punctuation">,</span> <span class="token keyword">func</span><span class="token punctuation">(</span>ctx iris<span class="token punctuation">.</span>Context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		ctx<span class="token punctuation">.</span><span class="token function">HTML</span><span class="token punctuation">(</span><span class="token string">&quot;&lt;b&gt;Hello Yaml!&lt;/b&gt;&quot;</span><span class="token punctuation">)</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
	<span class="token comment">// 通过文件配置 我们可以更加方便的切换开发环境配置和生产环境.</span>
	app<span class="token punctuation">.</span><span class="token function">Run</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span><span class="token function">Addr</span><span class="token punctuation">(</span><span class="token string">&quot;:9090&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> iris<span class="token punctuation">.</span><span class="token function">WithConfiguration</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span><span class="token function">YAML</span><span class="token punctuation">(</span><span class="token string">&quot;./config/config.yml&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="_4-自定义配置文件"><a href="#_4-自定义配置文件" class="header-anchor">#</a> 4 自定义配置文件</h2> <blockquote><p>这里我给大家演示如何使用<code>json</code>格式的配置文件来进行应用的配置,然后从应用程序中进行读取。我们在<code>config</code>目录下新建<code>config.json</code>文件，文件内容如下</p></blockquote> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
  <span class="token property">&quot;appname&quot;</span><span class="token operator">:</span> <span class="token string">&quot;IrisDemo&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;port&quot;</span><span class="token operator">:</span> <span class="token number">8000</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token keyword">package</span> main

<span class="token keyword">import</span> <span class="token punctuation">(</span>
	<span class="token string">&quot;encoding/json&quot;</span>
	<span class="token string">&quot;fmt&quot;</span>
	<span class="token string">&quot;github.com/kataras/iris/v12&quot;</span>
	<span class="token string">&quot;os&quot;</span>
<span class="token punctuation">)</span>

<span class="token comment">//读取json文件的结构体</span>
<span class="token comment">//json文件里面有多少项参数就对应多少个属性</span>
<span class="token keyword">type</span> Coniguration <span class="token keyword">struct</span> <span class="token punctuation">{</span>
	Appname <span class="token builtin">string</span> <span class="token string">`json:&quot;appname&quot;`</span>
	Port    <span class="token builtin">int</span>    <span class="token string">`json:&quot;port&quot;`</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	app <span class="token operator">:=</span> iris<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token comment">//打开文件</span>
	file<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> os<span class="token punctuation">.</span><span class="token function">Open</span><span class="token punctuation">(</span><span class="token string">&quot;./config/config.json&quot;</span><span class="token punctuation">)</span>
	<span class="token comment">//关闭文件</span>
	<span class="token keyword">defer</span> file<span class="token punctuation">.</span><span class="token function">Close</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	decoder <span class="token operator">:=</span> json<span class="token punctuation">.</span><span class="token function">NewDecoder</span><span class="token punctuation">(</span>file<span class="token punctuation">)</span>
	<span class="token comment">//声明要接收文件内容的结构体</span>
	conf <span class="token operator">:=</span> Coniguration<span class="token punctuation">{</span><span class="token punctuation">}</span>
	<span class="token comment">//读取json配置文件对应的值</span>
	err <span class="token operator">:=</span> decoder<span class="token punctuation">.</span><span class="token function">Decode</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>conf<span class="token punctuation">)</span>
	<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
		fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;Error:&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
	<span class="token punctuation">}</span>
	<span class="token comment">//读取文件中的端口号</span>
	fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>conf<span class="token punctuation">.</span>Port<span class="token punctuation">)</span>
	app<span class="token punctuation">.</span><span class="token function">Run</span><span class="token punctuation">(</span>iris<span class="token punctuation">.</span><span class="token function">Addr</span><span class="token punctuation">(</span><span class="token string">&quot;:8085&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br></div></div></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/go/web/iris-go/start.html" class="prev">
        Iris概览
      </a></span> <span class="next"><a href="/go/web/iris-go/handle-http.html">
        处理HTTP请求
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.1bc80adb.js" defer></script><script src="/assets/js/2.7c0608ab.js" defer></script><script src="/assets/js/98.9a231411.js" defer></script>
  </body>
</html>
